#!/bin/bash
#
# 2012/09/01 HA Backup
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

Date="`date +%Y%m%d`"
Backup_Dir="/home/backup"
dbuser="user"
dbpass="password"

#############################################################
All_DB="$(mysql -u $dbuser -p$dbpass -Bse 'show databases')"

if [ ! -d $Backup_Dir/$Date ]; then
        mkdir -p $Backup_Dir/$Date
        fi
for db in $All_DB
do
        if [ $db == 'information_schema' ];then
        continue
        fi
        mysqldump --single-transaction -quick -u $dbuser -p$dbpass $db | gzip > "$Backup_Dir/$Date/$db.gz"
done
find $Backup_Dir -mtime +30 -delete
sleep 5
find $Backup_Dir -empty -delete